﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Inspired.Euler
{
    public static class Problem112
    {
        static void Main()
        {
            Func<double, bool> isBouncy = number =>
            {
                var aux = number.ToString().ToCharArray().Select(c => (int)Char.GetNumericValue(c)).ToList();
                return aux.Where((n, i) => aux.FindIndex(i, a => a < n) != -1).Any() &&
                       aux.Where((n, i) => aux.FindIndex(i, a => a > n) != -1).Any();
            };

            double bounce = 0;
            for (double n = 1; ; n++)
            {
                if (isBouncy(n))
                    bounce++;

                //if ((bounce / n) == 0.5)
                //    Console.WriteLine(n);

                //if ((bounce / n) == 0.9)
                //    Console.WriteLine(n);

                if ((bounce / n) == 0.99)
                {
                    Console.WriteLine(n);
                    break;
                }
            }
        }
    }
}
